home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
t_os
/
et
/
src
/
buffer.c
< prev
next >
Wrap
Text File
|
1993-07-08
|
10KB
|
319 lines
#include "et.h"
int copy_buffer(int file_i, int mm, int *np, int replay_n)/*et*/
{
FILE *File, *Temp;
int i, dummy;
int key_n, csr_n;
unsigned f, m;
DIR Dir[1];
if (test_bit(G_f, f_DEMO|f_MAKE))
return;
switch(mm) {
case STORE:
if (file_i >= 4) {
G_nb.drive = *P_c[c_FILE_REPLAY];
switch(file_i) {
case 4:
f = f_REPLAY;
File = et_fopen(P_c[c_FILE_REPLAY], "wb", NULL);
et_fwrite(&f, sizeof(unsigned), 1, File);
et_fwrite(&dummy, sizeof(long), 1, File);
break;
case 5:
f = f_ERR;
File = et_fopen(P_c[c_FILE_REPLAY], "wb", NULL);
et_fwrite(&f, sizeof(unsigned), 1, File);
et_fwrite(&dummy, sizeof(long), 1, File);
break;
case 6:
f = f_ERR;
File = et_fopen(P_c[c_FILE_REPLAY], "ab", NULL);
fseek(File, 0L, 0);
et_fwrite(&f, sizeof(unsigned), 1, File);
et_fwrite(&replay_n, sizeof(long), 1, File);
_far_copy_buf(0x120, G_bf.pna, 0x14, P_v[v_VRAM], 0xa000);
et_fwrite(P_v[v_VRAM], 1, 0xa000, File);
et_fwrite(&G_pn.pna, sizeof(DIR*), 1, File);
et_fwrite(P_i[i_PNA_N], sizeof(int), 30, File);
et_fwrite(P_i[i_PNA_I], sizeof(int), 30, File);
fseek(File, replay_n, 0);
et_fwrite(&f, sizeof(unsigned), 1, File);
et_fwrite(&dummy, sizeof(long), 1, File);
break;
}
et_fwrite(P_v[v_VRAM], 1, 0xa000+sizeof(DIR*)+sizeof(int)*30*2,File);
et_fwrite(&G_nb.key, sizeof(int), 1, File);
et_fwrite(&G_nb.csr, sizeof(int), 1, File);
} else {
set_file_i(&P_c[c_FILE_BAK][8], file_i);
File = et_fopen(P_c[c_FILE_BAK], "wb", NULL);
G_nb.drive = *P_c[c_FILE_BAK];
}
f = test_bit(G_f, f_TROFF|f_AA|f_NN|f_REV|f_RND|f_VIEW|f_RR);
et_fwrite(&f, sizeof(G_f), 1, File);
et_fwrite(&G_nb.edge, sizeof(int), 1, File);
et_fwrite(G_et, sizeof(ET), G_nb.edge, File);
et_fwrite(G_edge, sizeof(EDGE), G_nb.edge, File);
et_fwrite(G_bf.edge, sizeof(EDGE), G_nb.edge, File);
key_n = nb_key(G_mv);
et_fwrite(&key_n, sizeof(int), 1, File);
et_fwrite(G_mv, sizeof(MOVE), key_n+1, File);
csr_n = nb_csr(P_c[c_CSR]);
et_fwrite(&csr_n, sizeof(int), 1, File);
et_fwrite(P_c[c_CSR], 1, csr_n+1, File);
et_fwrite(&G_pm, sizeof(PARAMETER), 1, File);
et_fwrite(&G_ps, sizeof(POSITION), 1, File);
et_fwrite(&G_nb.key_i, sizeof(int), 1, File);
if (file_i < 4) {
fclose(File);
return(0L);
}
et_fwrite(&G_nb.pna_drive, sizeof(int), 1, File);
et_fwrite(G_id, sizeof(IDX), 64, File);
et_fwrite(np, sizeof(int), 1, File);
if (G_nb.key) {
Temp = et_fopen(P_c[c_FILE_ICN_KEY], "rb", File);
copy_file(File, Temp, (int)G_nb.key * P_i[i_SIZE_ICN][0]);
fclose(Temp);
}
if (G_nb.csr) {
Temp = et_fopen(P_c[c_FILE_ICN_CSR], "rb", File);
copy_file(File, Temp, (int)G_nb.csr * P_i[i_SIZE_ICN][0]);
fclose(Temp);
}
set_file_i(&P_c[c_FILE_BAK][8], 0);
Temp = fopen(P_c[c_FILE_BAK], "rb");
if (!Temp) {
m = 0;
et_fwrite(&m, sizeof(int), 1, File);
} else {
fseek(Temp, 0L, 2);
m = ftell(Temp);
fseek(Temp, 0L, 0);
et_fwrite(&m, sizeof(int), 1, File);
copy_file(File, Temp, m);
fclose(Temp);
}
m = ftell(File);
fclose(File);
return(m);
break;
case RESTORE:
if (file_i >= 4) {
File = et_fopen(P_c[c_FILE_REPLAY], "rb", NULL);
fread(&dummy, sizeof(unsigned), 1, File);
if (file_i == 6) {
fread(&replay_n, sizeof(int), 1, File);
fseek(File, replay_n, 0L);
fread(&dummy, sizeof(unsigned), 1, File);
fread(&dummy, sizeof(unsigned), 1, File);
} else
fread(&dummy, sizeof(int), 1, File);
if (file_i == 4) {
fread(P_v[v_VRAM], 1, 0xa000, File);
_far_copy_buf(0x14, P_v[v_VRAM], 0x120, G_bf.pna, 0xa000);
fread(&G_pn.pna, sizeof(DIR*), 1, File);
fread(P_i[i_PNA_N], sizeof(int), 30, File);
fread(P_i[i_PNA_I], sizeof(int), 30, File);
} else {
fread(P_v[v_VRAM], 1, 0xa000+sizeof(DIR*)+sizeof(int)*30*2, File);
for (i = 0; i < 30; i++)
P_i[i_PNA_N][i] = -1;
Dir->dir = NULL;
Dir->next = NULL;
poke_dir(Dir, G_bf.pna);
G_pn.pna = (char*)G_bf.pna;
}
fread(&G_nb.key, sizeof(int), 1, File);
fread(&G_nb.csr, sizeof(int), 1, File);
} else {
set_file_i(&P_c[c_FILE_BAK][8], file_i);
File = et_fopen(P_c[c_FILE_BAK], "rb", NULL);
}
fread(&f, sizeof(G_f), 1, File);
res_bit(G_f, f_TROFF|f_AA|f_NN|f_REV|f_RND|f_VIEW|f_RR);
set_bit(G_f, f);
shaff_dot(P_dot[dot_FREE_AREA]);
shaff_dot(P_dot[dot_FREE_SAVE]);
copy_dot(P_dot[dot_FREE_WORK], P_dot[dot_FREE_SAVE]);
fread(&G_nb.edge, sizeof(int), 1, File);
if (G_nb.edge > G_nb.max_edge) {
int i_max;
i_max = sizeof(ET)*(G_nb.edge-G_nb.max_edge);
fread(G_et, sizeof(ET), G_nb.max_edge, File);
while (i_max--)
fgetc(File);
i_max = sizeof(EDGE)*(G_nb.edge-G_nb.max_edge);
fread(G_edge, sizeof(EDGE), G_nb.max_edge, File);
while (i_max--)
fgetc(File);
i_max = sizeof(EDGE)*(G_nb.edge-G_nb.max_edge);
fread(G_bf.edge, sizeof(EDGE), G_nb.max_edge, File);
while (i_max--)
fgetc(File);
G_nb.edge = G_nb.max_edge;
} else {
fread(G_et, sizeof(ET), G_nb.edge, File);
fread(G_edge, sizeof(EDGE), G_nb.edge, File);
fread(G_bf.edge, sizeof(EDGE), G_nb.edge, File);
}
fread(&key_n, sizeof(int), 1, File);
fread(G_mv, sizeof(MOVE), key_n+1, File);
fread(&csr_n, sizeof(int), 1, File);
fread(P_c[c_CSR], 1, csr_n+1, File);
fread(&G_pm, sizeof(PARAMETER), 1, File);
fread(&G_ps, sizeof(POSITION), 1, File);
fread(&G_nb.key_i, sizeof(int), 1, File);
G_pn.csr = P_c[c_CSR] + csr_n-1;
G_nb.et = *G_pn.csr;
if (file_i < 4) {
fclose(File);
return(0);
}
fread(&G_nb.pna_drive, sizeof(int), 1, File);
fread(G_id, sizeof(IDX), 64, File);
fread(np, sizeof(int), 1, File);
Temp = et_fopen(P_c[c_FILE_ICN_KEY], "wb", File);
if (G_nb.key) {
G_nb.drive = *P_c[c_FILE_ICN_KEY];
copy_file(Temp, File, (int)G_nb.key * P_i[i_SIZE_ICN][0]);
}
fclose(Temp);
Temp = et_fopen(P_c[c_FILE_ICN_CSR], "wb", File);
if (G_nb.csr) {
G_nb.drive = *P_c[c_FILE_ICN_CSR];
copy_file(Temp, File, (int)G_nb.csr * P_i[i_SIZE_ICN][0]);
}
fclose(Temp);
set_file_i(&P_c[c_FILE_BAK][8], 0);
Temp = et_fopen(P_c[c_FILE_BAK], "wb", File);
G_nb.drive = *P_c[c_FILE_BAK];
fread(&m, sizeof(int), 1, File);
copy_file(Temp, File, m);
m = ftell(File);
fclose(Temp);
fclose(File);
return(m);
break;
}
}
void copy_window(int pq_a[], VRAM buf_p[], unsigned seg, int mm)/*et*/
{
int p_i, q_i, p_d, p_n;
VRAM *vram_p;
p_i = pq_a[0];
q_i = pq_a[1];
p_d = (pq_a[2] - pq_a[0]) / 8 * sizeof(VRAM);
p_n = p_d / sizeof(VRAM);
vram_p = vram_addr(p_i, q_i, !G_nb.page);
switch(mm) {
case POKE:
while (1) {
_far_copy_buf(seg, buf_p, 0x120, vram_p, p_d);
vram_p += Y_INC;
q_i++;
if (q_i < pq_a[3])
buf_p += p_n;
else
break;
}
break;
case PEEK:
while (1) {
_far_copy_buf(0x120, vram_p, seg, buf_p, p_d);
vram_p += Y_INC;
q_i++;
if (q_i < pq_a[3])
buf_p += p_n;
else
break;
}
break;
}
}
void copy_edge(int rs_m, int ab_m)/*et*/
{
char *buf1_p, *buf2_p;
int edge_n;
buf1_p = G_bf.et_buf;
buf2_p = (char*)((int)G_bf.et_buf + sizeof(EDGE) * G_nb.max_edge);
switch(ab_m) {
case AFT:
edge_n = G_nb.edge;
break;
case BEF:
edge_n = G_nb.edge_b;
break;
}
switch(rs_m) {
case STORE:
_copy_buf(buf1_p, G_edge, sizeof(EDGE) * edge_n);
_copy_buf(buf2_p, G_bf.edge, sizeof(EDGE) * edge_n);
break;
case RESTORE:
_copy_buf(G_edge, buf1_p, sizeof(EDGE) * edge_n);
_copy_buf(G_bf.edge, buf2_p, sizeof(EDGE) * edge_n);
break;
case EXCHANGE:
_copy_buf(G_bf.edge_buf, G_edge, sizeof(EDGE) * G_nb.edge);
_copy_buf(G_edge, buf1_p, sizeof(EDGE) * G_nb.edge);
_copy_buf(buf1_p, G_bf.edge_buf, sizeof(EDGE) * G_nb.edge);
_copy_buf(G_bf.edge_buf, G_bf.edge, sizeof(EDGE) * G_nb.edge);
_copy_buf(G_bf.edge, buf2_p, sizeof(EDGE) * G_nb.edge);
_copy_buf(buf2_p, G_bf.edge_buf, sizeof(EDGE) * G_nb.edge);
break;
}
}
void load_vram(int offs, VRAM *vram_p, int size)/*et*/
{ /* v_KEY_TMP をバッファに使用 */
FILE *File;
char *c_p;
int i, j;
if (test_bit(G_f, f_DEMO))
return;
j = sizeof(VRAM[BUF_SIZE*2]);
set_file_i(&P_c[c_FILE_BAK][8], 3);
File = et_fopen(P_c[c_FILE_BAK], "rb", NULL);
c_p = (char*)vram_p;
while (size > 0) {
if (size < j)
i = size;
else
i = j;
fread(P_v[v_KEY_TMP], 1, i, File);
_memcpyfar(0x14, P_v[v_KEY_TMP], offs, c_p, i);
size -= j;
c_p += j;
}
fclose(File);
}
void save_vram(int offs, VRAM *vram_p, int size)/*et*/
{ /* v_KEY_TMP をバッファに使用 */
FILE *File;
char *c_p;
int i, j;
if (test_bit(G_f, f_DEMO))
return;
j = sizeof(VRAM[BUF_SIZE*2]);
set_file_i(&P_c[c_FILE_BAK][8], 3);
File = et_fopen(P_c[c_FILE_BAK], "wb", NULL);
G_nb.drive = *P_c[c_FILE_BAK];
c_p = (char*)vram_p;
while (size > 0) {
if (size < j)
i = size;
else
i = j;
_memcpyfar(offs, c_p, 0x14, P_v[v_KEY_TMP], i);
et_fwrite(P_v[v_KEY_TMP], 1, i, File);
size -= j;
c_p += j;
}
fclose(File);
}